package com.wwfish.cms.service.sysuser;

import com.wwfish.cms.model.CMSConstants;
import com.wwfish.cms.model.sysuser.SysRoleDto;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2010-8-19
 * Time: 14:45:48
 * To change this template use File | Settings | File Templates.
 */
public class SysRoleManagerImpl implements SysRoleManager {
    static List<SysRoleDto> roles = new ArrayList();

    public SysRoleDto saveAndUpdate(SysRoleDto dto) {
        if (dto.getId() == null) {
            dto.setId(new Long((int) (Math.random() * 10000)));
            dto.setCreateTime(new Date());
            roles.add(dto);
        } else
            dto.setUpdateTime(new Date());

        return dto;
    }

    public void delete(SysRoleDto dto) {
        roles.remove(dto);
    }

    public List<SysRoleDto> getAllRoles(Map<String, String> filter) {
        List r = new ArrayList();
        for (SysRoleDto role : roles) {
            if (role.getType().equals(filter.get("type")))
                r.add(role);
        }
        return r;
    }

    public SysRoleDto getRole(Long id) {
        return null;
    }
}
